package com.lewis.module.m2.api.record.controller;

import com.lewis.api.system.entity.BotFunctionMenu;
import com.lewis.common.core.entity.BaseResult;
import com.lewis.common.mongodb.MongodbUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 机器人指令菜单
 *
 * @author Lewis 398529803@qq.com 2022年8月9日, 009 15:24:43
 */
@Api(tags = "qq机器人")
@RestController
@RequestMapping("/record/qq/bot/function/menu")
public class RecordBotFunctionMenuController {

	@Resource
	private MongodbUtil mongodbUtil;

	@ApiOperation("指令菜单列表")
	@GetMapping("/list")
	public BaseResult list(BotFunctionMenu botFunctionMenu) {
		Query query = null;
		if (botFunctionMenu.getFatherId() == null) {
			query = mongodbUtil.createQuery("fatherId", "0");
		} else {
			query = mongodbUtil.createQuery("fatherId", botFunctionMenu.getFatherId());
		}
		return BaseResult.ok().setData(mongodbUtil.getListByQuery(query, BotFunctionMenu.class));
	}

	@ApiOperation("添加指令")
	@PostMapping("/add")
	public BaseResult add(@RequestBody BotFunctionMenu botFunctionMenu) {
		botFunctionMenu.setId(new ObjectId().toString());
		return BaseResult.ok().setData(mongodbUtil.save(botFunctionMenu));
	}

	@ApiOperation("批量删除指令")
	@PostMapping("/delete/{ids}")
	public BaseResult delete(@PathVariable String[] ids) {
		return mongodbUtil.deleteByIds(ids, BotFunctionMenu.class) ? BaseResult.ok() : BaseResult.fail();
	}
}
